home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / dhhelper.zip / DEMO2.PAS < prev    next >
Pascal/Delphi Source File  |  1990-06-12  |  8KB  |  174 lines

  1. Program Demo2;
  2. {===========================================================================}
  3. { This program demonstrates how to use  *.HLP  help files in conjunction
  4. { with Turbo Pascal 4.0 programs, and how to make use of user-specified
  5. { "hot keys" and cursor-selected user functions.
  6. {
  7. { First use The Helper to compile DEMO2.HLS (supplied with The Helper), to
  8. { create the help file DEMO2.HLP. Then run this program with Turbo Pascal 4
  9. { or higher. See how the user functions work. Then try writing your own user
  10. { functions and help files.
  11. {
  12. {-------- User functions defined in this program:
  13. { DEMO2.HLP contains 2 cursor options which cause a temporary exit to the
  14. { controlling program (this program) to execute user-defined procedures.
  15. { In addition, 4 "hot-key" functions are defined in this program, to cause
  16. { immediate temporary exit to this program. The cursor and hot-key options
  17. { defined here are:
  18. {    Cursor option 1 : Clear screen and write random numbers
  19. {    Cursor option 2 : Enter a filename and see if it exists
  20. {    Hot-key1      A : Type the letter "A" to sound the bell
  21. {    Hot-key2      C : Type "C" to toggle the category number display
  22. {    Hot-key3      R : Type "R" to redraw the screen (for animated screens)
  23. {    Hot-key4     F2 : No action - The F2=Print function has been suppressed
  24. {
  25. { These user-defined functions are incorporated into the procedure Get_Help,
  26. { so the rest of the program simply needs the statement "Get_Help(Categ);"
  27. { wherever and whenever it needs to access the help file (once the Help
  28. { filename has been specified). "Categ" is the requested category of Help,
  29. { though you can use "Get_Help(0);" to enter Help at the category last used.
  30. {===========================================================================}
  31.  
  32. {$M $4000,0,$4000}   {Set max heap size. This is only required if the *.hlp }
  33.                      {help files you use make use of the DOS shell facility.}
  34.                      {The stack and heap values should be at least $4000.   }
  35.  
  36. uses crt, help;
  37.  
  38. Var
  39.   HelpFileName : String; {The file name of the compiled help file to use}
  40.   Ch1,Ch2      : Char;   {Temporary character variables}
  41.  
  42. Procedure Write_Junk;
  43. {-----------------------------------------------------------------------}
  44. { Clear screen and write some random numbers until a key is pressed
  45. {-----------------------------------------------------------------------}
  46. Var
  47.   i,j : Byte;
  48.   x   : Real;
  49.   Ch  : Char;
  50. Begin
  51.   Window(1,1,80,25); TextAttr:=7; ClrScr;
  52.   Repeat
  53.     i:=Random(60); j:=Random(25); x:=1000*Random;
  54.     GotoXY(i,j); Write(x); Delay(10);
  55.   Until Keypressed;
  56.   Ch:=Readkey; If Ch=#0 then Ch:=Readkey;
  57. End;
  58.  
  59. Procedure Check_Filename(Filename : String);
  60. {-----------------------------------------------------------------------}
  61. { Check if a file exists, and print a message
  62. {-----------------------------------------------------------------------}
  63. Var
  64.   AnyFile : File;
  65.   i       : Byte;
  66. Begin
  67.   {$I-} If Filename<>'' then Assign(AnyFile,Filename);
  68.   Reset(AnyFile); i:=IOresult; {$I+}
  69.   Window(1,1,80,25); TextAttr:=7; GotoXY(1,24);
  70.   If i=0 then Write('File ',Filename,' exists.')
  71.   Else Write('File ',Filename,' does not exist.');
  72.   Write('  Press Enter to return...');
  73.   Readln;
  74. End;
  75.  
  76. Procedure Get_Help(Categ : Byte);
  77. {----------------------------------------------------------------------}
  78. { Use The Helper, after checking that it has been correctly initialised}
  79. {----------------------------------------------------------------------}
  80. Var
  81.   Ch1,Ch2 : Char;
  82.   Fname   : String;
  83. Begin
  84.   SaveHelpBG;  {Save background before opening a help screen}
  85.   If not HelpInitialised then Initialise_Help(HelpFileName);
  86.   If HelpInitialised then begin  {Use Help, check for exits via hot-keys}
  87.                                  {and user-defined cursor functions     }
  88.     Repeat
  89.       Use_Help(Categ);  {Use Help at this category (0=no change)}
  90.       Categ:=HelpCat;   {Update Categ, in case the user changed categories}
  91.       Ch1:=Upcase(HelpExitStr[1]);
  92.         {HelpExitStr contains the ASCII value of the hot-key used to exit}
  93.         {Help, or the cursor value if exit was by a cursor option:       }
  94.         {eg. "A"-->#65, F10-->#0#68,  cursor-->#255,#n                   }
  95.  
  96.       Case Ch1 of
  97.         'A' : Write(^G);                     {sound bell}
  98.         'C' : HelpShowCat:=not HelpShowCat;  {toggle category number display}
  99.         'R' : Begin End;                     {no action, redraw screen}
  100.        #255 : Begin                          {user-defined cursor functions}
  101.             Ch2:=HelpExitStr[2];
  102.                 If Ch2=#1 then Write_Junk
  103.                   {Write numbers - demo2.hls contains ^A(255,1) .... ^A, so}
  104.                   {HelpExitStr=#255#1 when this cursor option is selected  }
  105.  
  106.             Else If Ch2=#160 then begin
  107.                   {demo2.hls contains ^A(255,160) -------------- ^A, so    }
  108.                   {HelpExitStr=#255#160 when this cursor option is selected}
  109.                   Window(1,1,80,25); TextAttr:=7; GotoXY(1,24);
  110.                   Write('Enter any filename: ');
  111.                   Readln(Fname);
  112.                   Check_Filename(Fname);
  113.                 End;
  114.               End;
  115.       End;
  116.     Until Ch1=#27;     {Exit when Esc is pressed}
  117.   End;
  118.   RestoreHelpBG;     {Restore the original background when leaving Help}
  119. End;
  120.  
  121. BEGIN
  122. {-------Clear screen, and define the help file name}
  123.   ClrScr;
  124.   HelpFileName:='demo2.hlp';
  125.  
  126. {-------Define the hot-keys which will cause an exit from Help}
  127.   HelpExitChars:='aAcCrR';   {Normal (text) hot-keys = a, A, c, C, r, R }
  128.   HelpExitFuncChars:=#60;    {Extended (function keys) hot-keys #60 = F2}
  129.                              {  Note that the preceeding #0 for function}
  130.                              {  keys is not required. If F4, F5 and F6  }
  131.                              {  were required as hot-keys, set          }
  132.                              {  HelpExitFuncChars:=#62#63#64;           }
  133.                              {  Consult Turbo Pascal manual for values  }
  134.                              {  for Ctrl, Function and Alt keys.        }
  135.  
  136. {-------Define the heading for the Help window (optional, "Help" by default)}
  137.   HelpText:='DEMO2';
  138.  
  139. {-------Write some stuff on the screen, showing some options}
  140.   ClrScr; Writeln;
  141.   Writeln('DEMO2.pas  -  for use with help file DEMO2.hlp');
  142.   Writeln('-----------------------------------------------');
  143.   Writeln;
  144.   Writeln('Enter F1 for Help at same position as last time');
  145.   Writeln('      F2 for direct access to Help contents');
  146.   Writeln('      F3 for direct access to Help with Help');
  147.   Writeln('      F4 for direct access to DOS functions');
  148.   Writeln('      F5 for direct access to user-defined cursor options');
  149.   Writeln('      F6 for direct access to animation demonstration');
  150.   Writeln('      Esc to quit'); Writeln;
  151.   Write(' ---->');
  152.  
  153. {-------Demonstrate context-sensitive access to the help file by selecting }
  154. {       from the options.}
  155.   Repeat
  156.     GotoXY(7,13);
  157.     Ch1:=Upcase(Readkey);
  158.     If Ch1=#0 then begin  {extended character typed}
  159.       Ch2:=Readkey;
  160.       Case Ch2 of
  161.         #59 : Get_Help(0);  {F1 = Help, at last category accessed}
  162.         #60 : Get_Help(1);  {F2 = Goto Help contents}
  163.         #61 : Get_Help(2);  {F3 = Get Help at category 2 (Help with Help)}
  164.         #62 : Get_Help(7);  {F4 = Category 7 - DOS functions}
  165.         #63 : Get_Help(8);  {F5 = Category 8 - user functions}
  166.         #64 : Get_Help(9);  {F6 = Category 9 - animation demo}
  167.       End;
  168.     End;
  169.   Until Ch1=#27; {Esc=Quit}
  170.  
  171. {-------Clear screen and end}
  172.   ClrScr;
  173. END.
  174.